﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Capa_Entidad;

namespace Acceso_Datos.Clases_DAO
{
    public class clsAte_Historia_SocialDAO
    {
        private BDClinicaEntities ContextoDeObjs = new BDClinicaEntities();
        public bool Insertar(ATE_HISTORIA_SOCIAL Obj)
        {
            try
            {
                ContextoDeObjs.AddObject("ATE_HISTORIA_SOCIAL", Obj);
                ContextoDeObjs.SaveChanges();
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
        public bool Modificar(ATE_HISTORIA_SOCIAL obj)
        {

            try
            {
                ContextoDeObjs.AttachTo("ATE_HISTORIA_SOCIAL", obj);
                ContextoDeObjs.ObjectStateManager.ChangeObjectState(obj, System.Data.EntityState.Modified);
                ContextoDeObjs.SaveChanges();
            }
            catch (Exception)
            {
                return false;

            }
            return true;
        }
        public bool Eliminar(ATE_HISTORIA_SOCIAL obj)
        {
            try
            {
                ContextoDeObjs.AttachTo("ATE_HISTORIA_SOCIAL", obj);
                ContextoDeObjs.DeleteObject(obj);
                ContextoDeObjs.SaveChanges();
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
        public List<ATE_HISTORIA_SOCIAL> listar()
        {
            try
            {
                List<ATE_HISTORIA_SOCIAL> lista = new List<ATE_HISTORIA_SOCIAL>();
                var q = from c in ContextoDeObjs.ATE_HISTORIA_SOCIAL
                        select c;
                lista = q.ToList();
                return lista;
            }
            catch (Exception ex)
            {

                throw ex;
            }

        }


        public List<ATE_HISTORIA_SOCIAL> getHistoria(int idHistoriaSocial)
        {
            List<ATE_HISTORIA_SOCIAL> lista = new List<ATE_HISTORIA_SOCIAL>();
            try
            {
               
                var q = from c in ContextoDeObjs.ATE_HISTORIA_SOCIAL
                        where c.PAC_ID_PACIENTE == idHistoriaSocial
                        select c;
                lista = q.ToList();
                return lista;
            }
            catch (Exception ex)
            {
                return lista;
                throw ex;
            }

        }

    }
}
